import 'package:flutter/widgets.dart';
import 'package:mvvm_provider/base/base_state.dart';
import 'package:mvvm_provider/base/base_view_model.dart';
import 'package:provider/provider.dart';

/// 不需要根据数据来显示的页面

class ConsumerWidget<T extends BaseViewModel<S>, S extends BaseState> extends StatelessWidget {
  const ConsumerWidget({super.key, required this.builder, this.child});

  final Widget Function(BuildContext context, S state, Widget? child) builder;
  final Widget? child;
  @override
  Widget build(BuildContext context) {
    return Consumer<T>(
      builder: (context, viewModel, child) {
        return builder(context, viewModel.state, child);
      },
      child: child,
    );
  }
}
